﻿using System;
using System.Collections.Generic;
using System.Text;
using rkShared.Serialization;

namespace rkShared
{
    [Serializable]
    public class Player : IBinarySerializable
    {
        //Oyuncunun ismi
        private String name;
        private Tank tank;
        private int killCount = 0;


        public Player()
        {
            tank = new Tank();
        }


        public String Name
        {
            get { return name; }
            set { name = value; }
        }

        public Tank Tank
        {
            get { return tank; }
        }
        public int KillCount
        {
            get { return killCount; }
        }
        public Guid ClientID { get; set; }

        #region IBinarySerializable Members

        public void SerializeToDictionary(rkShared.BEncode.BEncodedDictionary dictionary)
        {
            dictionary.Add("n", this.name, Encoding.UTF8);
            dictionary.Add("t", this.tank);
            dictionary.Add("k", this.killCount);
            dictionary.Add("c", this.ClientID.ToString());
        }
        public void DeserializeFromDictionary(rkShared.BEncode.BEncodedDictionary dict)
        {
            this.name = dict.GetString("n", Encoding.UTF8);
            this.killCount = dict.GetInt("k");
            this.tank = dict.GetIBinarySerializable<Tank>("t");
            if (dict.ContainsKey("c"))
                this.ClientID = new Guid(dict.GetString("c"));
        }

        #endregion
    }
}
